import { IcommentItem } from '@/utils/comment';
import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';
import {getComment} from '../services/index';

export interface IndexModelState {
    comment:Array<IcommentItem>
}

export interface IndexModelType {
  namespace: 'comment';
  state: IndexModelState;
  effects: {
    getComment: Effect;
  };
  reducers: {
    save: Reducer<IndexModelState>;

  };
  subscriptions?: { setup: Subscription };
}

const IndexModel: IndexModelType = {
  namespace: 'comment',

  state: {
    comment: [],
  },

  //异步action
  effects: {
    *getComment({ payload }, { call, put }) {
      let results = yield call(getComment,payload);
      yield put({
        type:'save',
        payload:{
            comment:results.data
        }
      })
    },
  },
  //同步action
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },

  },
 
};

export default IndexModel;